package gervosou;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

public class VueConsultComptePerso extends Vue {
	
	private JPanel panel;
	
	private JFrame frmVueConsultComptePerso;
	
	private static final long serialVersionUID = 1L;
	
	private JLabel lblNumroDeCompte;
	private JLabel lblNomDuClient;
	private JLabel lblPrenomDuClient;
	private JLabel lblAdresse;
	private JLabel lblDateDeNaissance;
	private JLabel lblNumeroDuCompte;
	private JLabel lblSoldeDuCompte;
	private JLabel lblDecouvertAutorise;
	
	private JSeparator separator1;
	private JSeparator separator2;
	
	private JTextField textFieldnum_compte;
	private JTextField textFieldnom_client;
	private JTextField textFieldprenom_client;
	private JTextField textFieldadresse;
	private JTextField textFielddate_naiss;
	private JTextField textFieldnum_compte_2;
	private JTextField textFieldsolde_compte;
	private JTextField textFielddecouvert_autoris;
	
	private JButton btnQuitter;
	private JButton btnAnnuler;
	private JButton btnRechercher;
	
	public VueConsultComptePerso(Controleur c) {
	
		super (c);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 500, 500);
		setTitle("Consultation du compte personnel");
		
		panel = new JPanel();
		panel.setBorder(new EmptyBorder(0, 0, 0, 0));
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		textFieldnum_compte = new JTextField();
		textFieldnum_compte.setBounds(296, 26, 114, 19);
		panel.add(textFieldnum_compte);
		textFieldnum_compte.setColumns(10);
		
		lblNumroDeCompte = new JLabel("Numéro de compte :");
		lblNumroDeCompte.setBounds(130, 28, 133, 15);
		panel.add(lblNumroDeCompte);
		
		btnRechercher = new JButton("Rechercher");
		btnRechercher.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String numCompte = textFieldnum_compte.getText();
				getControleur().rechComptePerso(numCompte);
			}
		});
		btnRechercher.setBounds(58, 75, 107, 25);
		panel.add(btnRechercher);
		
		btnAnnuler = new JButton("Annuler");
		btnAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueConsultComptePerso.this);
			}
		});
		btnAnnuler.setBounds(277, 75, 107, 25);
		panel.add(btnAnnuler);
		
		separator1 = new JSeparator();
		separator1.setBounds(79, 130, 275, 2);
		panel.add(separator1);
		
		lblNomDuClient = new JLabel("Nom du client :");
		lblNomDuClient.setBounds(156, 168, 107, 15);
		panel.add(lblNomDuClient);
		
		lblPrenomDuClient = new JLabel("Prenom du client :");
		lblPrenomDuClient.setBounds(139, 195, 124, 15);
		panel.add(lblPrenomDuClient);
		
		lblAdresse = new JLabel("Adresse :");
		lblAdresse.setBounds(194, 222, 62, 15);
		panel.add(lblAdresse);
		
		lblDateDeNaissance = new JLabel("Date de naissance :");
		lblDateDeNaissance.setBounds(132, 249, 124, 15);
		panel.add(lblDateDeNaissance);
		
		textFieldnom_client = new JTextField();
		textFieldnom_client.setEditable(false);
		textFieldnom_client.setBounds(296, 166, 114, 19);
		panel.add(textFieldnom_client);
		textFieldnom_client.setColumns(10);
		
		textFieldprenom_client = new JTextField();
		textFieldprenom_client.setEditable(false);
		textFieldprenom_client.setBounds(296, 193, 114, 19);
		panel.add(textFieldprenom_client);
		textFieldprenom_client.setColumns(10);
		
		textFieldadresse = new JTextField();
		textFieldadresse.setEditable(false);
		textFieldadresse.setBounds(296, 220, 114, 19);
		panel.add(textFieldadresse);
		textFieldadresse.setColumns(10);
		
		textFielddate_naiss = new JTextField();
		textFielddate_naiss.setEditable(false);
		textFielddate_naiss.setBounds(296, 247, 114, 19);
		panel.add(textFielddate_naiss);
		textFielddate_naiss.setColumns(10);
		
		separator2 = new JSeparator();
		separator2.setBounds(58, 282, 310, 2);
		panel.add(separator2);
		
		lblNumeroDuCompte = new JLabel("Numero du compte :");
		lblNumeroDuCompte.setBounds(127, 296, 136, 15);
		panel.add(lblNumeroDuCompte);
		
		textFieldnum_compte_2 = new JTextField();
		textFieldnum_compte_2.setEditable(false);
		textFieldnum_compte_2.setBounds(296, 296, 114, 19);
		panel.add(textFieldnum_compte_2);
		textFieldnum_compte_2.setColumns(10);
		
		lblSoldeDuCompte = new JLabel("Solde du compte  :");
		lblSoldeDuCompte.setBounds(139, 333, 116, 15);
		panel.add(lblSoldeDuCompte);
		
		lblDecouvertAutorise = new JLabel("Decouvert autorisé :");
		lblDecouvertAutorise.setBounds(130, 369, 133, 15);
		panel.add(lblDecouvertAutorise);
		
		textFieldsolde_compte = new JTextField();
		textFieldsolde_compte.setEditable(false);
		textFieldsolde_compte.setBounds(296, 331, 114, 19);
		panel.add(textFieldsolde_compte);
		textFieldsolde_compte.setColumns(10);
		
		textFielddecouvert_autoris = new JTextField();
		textFielddecouvert_autoris.setEditable(false);
		textFielddecouvert_autoris.setBounds(296, 367, 114, 19);
		panel.add(textFielddecouvert_autoris);
		textFielddecouvert_autoris.setColumns(10);
		
		btnQuitter = new JButton("Quitter");
		btnQuitter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueConsultComptePerso.this);
			}
		});
		btnQuitter.setBounds(182, 396, 107, 25);
		panel.add(btnQuitter);
	}

	public void alimente(ComptePerso cp) {
		
		ClientPhysique clp = cp.getClientPhysique();
		textFieldnom_client.setText(clp.getNom());
		textFieldprenom_client.setText(clp.getPrenom());
		textFieldadresse.setText(clp.getAdresse());
		textFielddate_naiss.setText(ESDate.ecrireDate(clp.getDateNaissance()));
		textFieldnum_compte_2.setText(String.valueOf(cp.getNumero()));
		textFieldsolde_compte.setText(String.valueOf(cp.getSolde()));
		textFielddecouvert_autoris.setText(String.valueOf(cp.getDecouvertAutorise()));
	}
	
	public void setEtat (int etat){
		switch (etat) {
		case initiale: {
			btnQuitter.setEnabled(false);
			btnAnnuler.setEnabled(true);
			break;
			}
		case finale: {
			btnQuitter.setEnabled(true);
			btnAnnuler.setEnabled(false);
			break;
			}
		}
	}

}